<template>
<div>
  <div>
    <el-input v-model="sid" placeholder="请输入切换的用户"></el-input>
    <el-input v-model="role" placeholder="请输入对于角色"></el-input>
    <el-button type="warn" @click="changeUser">切换用户</el-button>
  </div>
<!--  待审核列表-->
  <div style="margin-top: 50px">
    <el-table
        :data="data"
        border
        style="width: 100%">
      <el-table-column
          prop="id"
          label="申请流程id"
          sortable>
      </el-table-column>
      <el-table-column
          prop="cuid"
          label="申请id">
      </el-table-column>
      <el-table-column
          prop="name"
          label="任务名称">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="150">
        <template #default="scope">
          <el-button @click="advice(scope.row,'yes')" type="success" size="small">同意</el-button>
          <el-button type="danger" size="small" @click="advice(scope.row,'no')">驳回</el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</div>
</template>

<script setup>
import {ref,onMounted} from "vue";
import {useStore} from 'vuex'
import axios from "axios";

const store=useStore()
const data=new ref([])
const sid=new ref(1)
const role=new ref("leader")
onMounted(()=>{
  loadData()
})
const loadData=()=>{
  //请求接口 查询待审核列表
  //axios get
  axios.get("cu/task?role="+role.value).then(res=>{
    data.value=res.data.data;
  })
}
const changeUser=()=>{
  //更改VueX
  store.commit("setToken",sid.value);
  loadData();

}
const advice=(row,result)=>{
  console.log(row);
  console.log(result);
  //审核 请求接口 axios
  var ad={
    cuid: row.cuid,
    id: row.id,
    result: result,
    role: role.value
  }
  console.log(ad)
  axios.post("cu/advice",ad).then(res=>{
    if(res.data.code==0){
      //审核成功
      loadData();
    }else{
      alert("审核失败，请重试！")
    }
  })
}
</script>

<style scoped>

</style>
